<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link href="__MODES__/assets/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__CSS__/style.css" />
		<link href="__MODES__/assets/css/codemirror.css" rel="stylesheet">
		<link rel="stylesheet" href="__MODES__/assets/css/ace.min.css" />
		<link rel="stylesheet" href="__MODES__/assets/css/font-awesome.min.css" />
		<!--[if IE 7]>
	  <link rel="stylesheet" href="__MODES__/assets/css/font-awesome-ie7.min.css" />
	<![endif]-->
		<!--[if lte IE 8]>
	  <link rel="stylesheet" href="__MODES__/assets/css/ace-ie.min.css" />
	<![endif]-->
		<script src="__PLUGINS__/jquery-1.9.1.min.js"></script>
		<script src="__MODES__/assets/js/bootstrap.min.js"></script>
		<script src="__MODES__/assets/js/typeahead-bs2.min.js"></script>
		<script src="__MODES__/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="__MODES__/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="__MODES__/assets/js/ace-elements.min.js"></script>
		<script src="__MODES__/assets/js/ace.min.js"></script>
		<title>编辑</title>

		<script src="__PLUGINS__/layer/layer.js"></script>
		<script src="__PLUGINS__/common.js"></script>

	<body>
		<div class="margin clearfix">
			<div class="stystems_style">
				<div class="tabbable">
					<div class="tab-content">
						<form name="agent-form" id="agent-form" action="{:Url('Admin/Agent/aedit')}">
						<div id="home" class="tab-pane active">
							{if $AGENT_GRADE == 1}
							<div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i></i>上级代理： </label>
								<div class="col-sm-8">
									<select name='agent_uid' onchange="onchange()" class="col-xs-10 " style="margin-left:10px ">
										<option value="0">系统代理</option>
										{volist name='list' id='v'}
											<option value="{$v.agent_id}" {if $agent['agent_pid']==$v.agent_id} selected {/if}>{$v.agent_name}-{$v.agent_phone}</option>
										{/volist}
									</select>
								</div>
							</div>
							{else}
							<div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i></i>上级代理： </label>
								<div class="col-sm-8">
									<select name='agent_uid'  class="col-xs-10 " style="margin-left:10px ">
										<option value="0">系统代理</option>
										{volist name='list' id='v'}
											<option value="{$v.agent_id}" {if $agent['agent_pid']==$v.agent_id} selected {/if}>{$v.agent_name}-{$v.agent_phone}</option>
										{/volist}
									</select>
								</div>
							</div>
							{/if}

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i></i>用户名： </label>
								<div class="col-sm-8">
									<input  type="text" name="account" value="{$agent.agent_account}" id="account"  class="col-xs-10 ">
								</div>
								<input type="hidden" name="aid" value="{$agent.agent_id}">
								<input type="hidden" name="" id="agent_grade_id" value="{$agent['agent_grade']}" />
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i></i>姓名： </label>
								<div class="col-sm-8">
									<input type="text" name="name" value="{$agent.agent_name}" id="name" class="col-xs-10 ">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>手机号： </label>
								<div class="col-sm-8">
									<input type="number" name="phone" value="{$agent.agent_phone}" id="phone"   class="col-xs-10 ">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>身份证： </label>
								<div class="col-sm-8">
									<input type="text" value="{$agent.agent_idcard}" id="idcard" name="idcard" class="col-xs-10 ">
								</div>
							</div>
		                  	{if $AGENT_GRADE == 1}
							<div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>添加代理等级： </label>
								<div class="col-sm-8">
									<select name='grade_id' id="grade_id" class="col-xs-10 " style="margin-left:10px ">
										<option value="">请选择</option>
									</select>
								</div>
							</div>
		                  	{else}
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>客户容纳人数： </label>
								<div class="col-sm-8">
									<input type="number" id="capacity" value="{$agent.agent_can_allot}" min="0" name="capacity" class="col-xs-10 ">
								</div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>签署还款费率% </label>
								<div class="col-sm-8">
									<input type="number" step="0.01" value="{$re1}" value="" min="0" id="hk" name="hk" class="col-xs-10 ">
								</div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>签署收款款费率% </label>
								<div class="col-sm-8">
									<input type="number" value="{$re2}" step="0.01" name="sk" min="0" id="sk" class="col-xs-10 ">
								</div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>代理升级费率‰ </label>
								<div class="col-sm-8">
									<input type="number" value="{$re3}" step="0.01" name="sj" min="0" id="sj" class="col-xs-10 ">
								</div>
							</div>
							{/if}
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>代理城市 </label>
								<div class="col-sm-8">
									<input type="text" value="{$agent.agent_city}" id="city" name="city" class="col-xs-10 ">
								</div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i>*</i>公司名 </label>
								<div class="col-sm-8">
									<input type="text"  value="{$agent.agent_company}" id="agent_company" name="agent_company" class="col-xs-10 ">
								</div>
							</div>
							<div class="form-group"><label class="col-sm-2 control-label no-padding-right" for="form-field-1"><i></i>状态： </label>
								<div class="col-sm-8">
									<select name='agent_state' class="col-xs-10 " style="margin-left:10px ">
										<option value="0" {if $agent['agent_state']==0} selected {/if}>正常</option>
										<option value="1" {if $agent['agent_state']==1} selected {/if}>冻结</option>
									</select>
								</div>
							</div>
							
							<div class="Button_operation">
								<button  onclick="saveSubmit();" id="agent-btn" class="btn btn-primary radius" type="button"><i class="fa fa-save "></i>&nbsp;保存</button>
							</div>
						</div>
						</form>
					</div>
				</div>
			</div>

		</div>
		
		<script>
			function  saveSubmit () {
				var url    = $("#agent-form").attr('action');
				
				
				var account = $('#account').val();
				if(account==''){
					layer.msg('请输入账号');
					return false;
				}
				var password = $('#password').val();
				if(password==''){
					layer.msg('请输入登陆密码');
					return false;
				}
				var name = $('#name').val();
				if(name==''){
					layer.msg('请输入代理姓名');
					return false;
				}
				var phone = $('#phone').val();
				if(phone==''){
					layer.msg('请输入手机号');
					return false;
				}
				var idcard = $('#idcard').val();
				if(idcard==''){
					layer.msg('请输入身份证号码');
					return false;
				}
				var capacity = $('#capacity').val();
				if(capacity==''){
					layer.msg('请输入承载量');
					return false;
				}
				var hk = $('#hk').val();
				if(hk==''){
					layer.msg('请输入还款费率');
					return false;
				}
				var sk = $('#sk').val();
				if(sk==''){
					layer.msg('请输入收款款费率');
					return false;
				}
				var sj = $('#sj').val();
				if(sj==''){
					layer.msg('请输入收款款费率');
					return false;
				}
				var city = $('#city').val();
				if(city==''){
					layer.msg('请输入代理所在城市');
					return false;
				}
				
				var data   = $("#agent-form").serialize();

				ajaxPost(url,$("#agent-btn"),data,function (r) {
					if(r.error == '0'){
						// layer.msg(r.msg);
	                    // setTimeout(function(){
						window.location.href="{:Url('agent/index')}"
	                    // },1500) 
		            	$("#agent-btn").removeAttr('disabled');

		            }

		            //location.reload();
		        })
			}

		onchange($("#agent_grade_id").val());

        function onchange(id){ //监听下拉列表的change事件
        	if(id==''){
        		var address = $(this).val();  //获取下拉列表选中的值
        	}else{
        		var address = id;  //获取下拉列表选中的值
        	}
            
            var url    = "{:Url('agent/Twolinkage')}";
            $.ajax({
                type:'post',
                url:url,
                data:{id:address},
                dataType:'json',
                success:function(data){  //请求成功回调函数
                    
                    if(data.error == 0){  //判断状态码，200为成功
                        var option = '<option value="">请选择</option>';
                        for(var i=0;i<data.data.length;i++){  //循环获取返回值，并组装成html代码
                        	if(address==data.data[i].grade_id){
                        		option +='<option value="'+data.data[i].grade_id+'" selected>'+data.data[i].grade_name+'</option>';
                        	}else{
                        		option +='<option value="'+data.data[i].grade_id+'">'+data.data[i].grade_name+'</option>';
                        	}
                            
                        }
                        $("#grade_id").html(option);  //js刷新第二个下拉框的值
                    }else{
                        layer.msg(data.msg);
						return false;
                    }
                },
            });
        };
		</script>
	</body>

</html>